package com.sylar.sys.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sylar.general.action.GeneralAction;
import com.sylar.general.common.RespMsg;
import com.sylar.general.common.page.PageUtil;
import com.sylar.sys.model.Menu;
import com.sylar.sys.model.User;
import com.sylar.sys.service.UserService;


@RequestMapping("/user")
@Controller
@Scope("prototype")
public class UserAction extends GeneralAction {
	
	@Autowired
	private UserService userService;
	
	
	@RequestMapping("getList")
	public String getList(){
		return "user/user_list";
	}
	
	@ResponseBody
	@RequestMapping("getPage")
	public Object getPage(PageUtil page, User user){
		page.setQueryObj(user);
		page = userService.getPageList(page);
		return page;
	}
	@RequestMapping("gotoAdd")
	public String gotoAdd(ModelMap map){
		return "user/user_add";
	}
	
	@ResponseBody
	@RequestMapping("save")
	public Object save(User user){
		if(user!=null && user.getUserId()!=null){
			userService.upd(user);
		} else {
			userService.add(user);
		}
		return RespMsg.success();
	}
	
	@ResponseBody
	@RequestMapping("delete")
	public Object delete(String ids){
		userService.delMore(ids);
		return RespMsg.success();
	}
	
	@RequestMapping("gotoUpd")
	public Object gotoAdd(Integer userId,ModelMap map){
		User user = userService.getById(userId);
		map.put("user", user);
		return "user/user_edit";
	}
}
